#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
using ld = long double;
const ld PI = 3.1415926535897932384626433832795028841971693993751058209749445;
const ll N = 1e6 + 10, INF = 0x3f3f3f3f;

ll kpow(ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void solve()
{
    ll n;
    while (cin >> n) {
        ll res = 1e9;
        while (n--) {
            ll t1, m1, t2, m2, t3, m3;
            scanf("%lld:%lld", &t1, &m1);
            scanf("%lld:%lld", &t2, &m2);
            scanf("%lld:%lld", &t3, &m3);
            if (t1 > t3) t3 = t1, m3 = m1;
            else if (t1 == t3 && m1 > m3) m3 = m1;

            ll m;
            cin >> m;
            vector<ll> a(m);
            for (auto& x : a)
                cin >> x;

            ll y = t2 * 60 + m2 - (t1 * 60 + m1);
            ll s = t3 * 60 + m3 - (t1 * 60 + m1);
            ll mia = t1 * 60 + m1, mib = t2 * 60 + m2, mic = t3 * 60 + m3;

            ll f, ans = 1e9;
            for (ll i = s; i <= y; i++) {
                ll sum = 0;
                for (ll j = 0; j < m; j++) {
                    sum += a[j] * kpow(i, j);
                }
                f = abs(y * sin((sum)));
                if (mic + f + i - s <= mib) {
                    ans = min(ans, mic + i - s + f);
                }
            }
            res = min(ans, res);
        }
        if (res == 1e9)
            printf("Oh No!\n");
        else {
            printf("%02lld:%02lld\n", res / 60, res % 60);
        }
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    // cin>>T;
    for (ll i = 1; i <= T; i++) {
        solve();
    }
}